#include <stdio.h>
#include <gtk/gtk.h>
#include <mysql/mysql.h>

void
on_window_destroy( GObject *object, gpointer user_data)
{
    gtk_main_quit();
}

int
dostuff( GtkWidget *widget, gpointer data ){
    MYSQL *conn;
    MYSQL_ROW row;
    MYSQL_RES *result;
    int i, num_fields;

    conn = mysql_init(NULL);
    if(mysql_real_connect(conn, "localhost", "root", "jejeje", "test", 0, NULL, 0) == NULL)
    {
        printf("Error %u: %s\n", mysql_errno(conn), mysql_error(conn));
        return 0;
    }
    printf("Lista de MARICAS en la DB\n");
    mysql_query(conn, "SELECT * FROM rand_numbers");
    result = mysql_store_result(conn);
    num_fields = mysql_num_fields(result);

    while ((row = mysql_fetch_row(result)))
    {
        for(i = 0; i < num_fields; i++)
        {
            printf("%s ", row[i] ? row[i] : "NULL");
        }
        printf("\n");
    }
    mysql_free_result(result);
    mysql_close(conn);

}

void 
showGeneralWindow( GtkWidget *widget, gpointer data){
    GtkWidget *gralWindow;
    GtkBuilder *builder;
    builder = gtk_builder_new();
    gtk_builder_add_from_file(builder, "../gui/cedLibre.glade", NULL);

    gralWindow = GTK_WIDGET(gtk_builder_get_object(builder, "generalWindow"));
    gtk_widget_show(gralWindow);

}

int main(int argc, char* argv[]){
    GtkBuilder *builder;
    GtkWidget  *window;
 
    gtk_init (&argc, &argv);

    builder = gtk_builder_new();
    gtk_builder_add_from_file(builder, "../gui/cedLib.glade", NULL);
    window = GTK_WIDGET(gtk_builder_get_object(builder, "mainWindow"));
    gtk_builder_connect_signals(builder, NULL);

    g_object_unref(G_OBJECT(builder));

   
    gtk_widget_show(window);

    gtk_main();

    return 0;
}
